#include "ind16.h"


ind16::ind16(QDate date_, track track_, QList<rider *> r)
{
    standings_m.rider_points.resize(16);
    table_of_heats.heats.resize(20);
    for(int i = 0; i < 20; i++)
    {
        table_of_heats.heats[i].start_positions.resize(4);
        table_of_heats.heats[i].number = i;
    }
    QList<QStringList> table_from_file = CSV.read("rules/ind16.csv");
    for (int i = 0; i< table_from_file.size(); i++)
    {
        for (int n = 0; n < 4; n++)
        {
            table_of_heats.heats[i].number = i;
            table_of_heats.heats[i].start_positions[n].helmet = table_from_file[i][n][2];
            table_of_heats.heats[i].start_positions[n].rider_number = table_from_file[i][n].left(2).toInt()-1;
            table_of_heats.heats[i].start_positions[n].number = n;
        }
    }
    riders_list = r.toVector();
    date = date_;
    h = new heat(track_.name);
    event_type = "ind16";
    heat_number = 0;
    containers.resize(1);
}
QStringList ind16::runHeat(QList<rider>& r)
{
    QList<heat_rider*> riders;
    for (int i = 0; i < 4; i++)
    {
        riders << &riders_list[table_of_heats.heats[heat_number].start_positions[i].rider_number]->rider_h;
        riders[i]->clear();
        riders[i]->helmetColour = table_of_heats.heats[heat_number].start_positions[i].helmet;
        riders[i]->startPosition = table_of_heats.heats[heat_number].start_positions[i].number;
    }

    h->runHeat(riders, true);
    QStringList txt;
    QString stra;
    for (int i = 0; i < riders.size(); i++)
    {
        standings_m.rider_points[table_of_heats.heats[heat_number].start_positions[i].rider_number] << 4 - riders[i]->place;
        stra = "<b>" + QString::number(4 - riders[i]->place)+ " " + r[riders[i]->id].surname + "<\b>";
        txt << stra;
    }
    heat_number++;
    return txt;
}
